<template>
	<view>
		<view class="column align-items-center" style="margin-top: 30rpx;">
			<view class="column" style="width: 450rpx;margin: 0rpx auto;">
				<text style="color: #ED0F1A;margin: 0rpx auto;font-size: 50rpx;">提现金额</text>
				<text style="color: #00aaff;margin: 0rpx auto;font-size: 50rpx;">{{moneyArr.lmDeposit.amountValue}}元</text>
				<view class="row">
					<text class="serial-number">①</text>
					<text>{{moneyArr.lmDeposit.scoreValue}}可提现云豆</text>
				</view>
				<view class="row" style="margin-left: 100rpx;">
					<text>{{moneyArr.lmDeposit.scoreValue}}/{{moneyArr.lmDeposit.scoreValue}}</text>
					<zywork-icon type="icon-jianchaqueren-kuai" color="#00aaff" size="40"></zywork-icon>
				</view>
				<view class="row ">
					<text class="serial-number">②</text>
					<text>当天邀请{{moneyArr.lmDeposit.inviteeCount}}个新用户</text>
				</view>
				<view class="row align-items-center" style="margin-right: 17rpx;">
					<text :style="moneyArr.inviteeCount<moneyArr.lmDeposit.inviteeCount?'color: #ff0000;':''">{{moneyArr.inviteeCount}}/{{moneyArr.lmDeposit.inviteeCount}}</text>
					<zywork-icon v-if="moneyArr.inviteeCount>=moneyArr.lmDeposit.inviteeCount" type="icon-jianchaqueren-kuai" color="#00aaff" size="40"></zywork-icon>
				</view>
			</view>
			<view class="button" @click="logoTime">
				邀请微信好友
			</view>
			<view class="button" @click="withdrawalWechat">
				立即提现
			</view>
			<view class="column align-items-center">
				<view class="column align-items-center" style="border: solid 1rpx #EEEEEE;border-radius: 50%;width: 320rpx;height: 320rpx;">
					<canvas id="qrcode1" @click="previewImage" canvas-id="qrcode1" :style="`width: ${extentRpx}rpx;height: ${extentRpx}rpx;`" />
				</view>
				<text @click="previewImage">点击面对面扫码</text>
				
			</view>
		</view>
		<view class="" style="text-align: center;margin-top: 50rpx;">
			打开微信点击右上角扫一扫> 扫码此二维码
		</view>
	<uni-popup ref="share" background-color="#fff" type="share"><uni-popup-share @select="select"></uni-popup-share></uni-popup>
	</view>
</template>

<script>
	import uQRCode from '@/components/uqrcode/common/uqrcode.js'
	export default {
		data() {
			return {
				extentRpx: 230,
				qrcodeSrc: "",
				// BASE_URL:"https://yunzhuan.zgwlkj.cn/yunzhuan",
				BASE_URL: "http://yunzhuan.zgwlkj.cn/ceshiyunzhuan",
				userInfo: {},
				moneyArr:""
			};
		},
		onUnload() {
			console.log("卸载页面，返回上一页")
			uni.hideLoading()
		},
		onLoad(data) {
			if(data.moneyArr){
				this.moneyArr = JSON.parse(data.moneyArr)
			}
		},
		created() {
			let pxSize = uni.upx2px(this.extentRpx);
			this.userInfo = uni.getStorageSync(this.$util.USER_INFO)
			setTimeout(() => {
				console.log('邀请码', this.userInfo.rcode)
				if (uni.getStorageSync(this.$util.APP_VERSION)) {
					let url = uni.getStorageSync(this.$util.APP_VERSION);
					this.BASE_URL = url.webUrl
				}
				if(!this.qrcodeSrc){
					uni.showLoading({
						title: "加载邀请码.."
					})
					
					uQRCode.make({
						canvasId: 'qrcode1',
						componentInstance: this,
						size: pxSize,
						margin: 10,
						text: this.BASE_URL + '/#/?rcode=' + this.userInfo.rcode,
						backgroundColor: '#ffffff',
						foregroundColor: '#000000',
						fileType: 'png',
						errorCorrectLevel: uQRCode.errorCorrectLevel.H
					})
					.then(res => {
						uni.hideLoading()
						this.qrcodeSrc = res.tempFilePath
					})
				}
			}, 500)
		},
		onShow() {
			
		},
		methods: {
			async withdrawalWechat(){
				if(this.moneyArr.inviteeCount < this.moneyArr.lmDeposit.inviteeCount){
					this.$util.showInfoToast(`您还需要邀请${this.moneyArr.lmDeposit.inviteeCount-this.moneyArr.inviteeCount}人才可提现`)
					return
				}
				
				let parameter = {
					id: withdrawalRulesId,
					type:this.moneyArr.type,
				}
				if(parameter.type === 3){
					parameter.cardNo = this.moneyArr.cardNo
				}
				const {
					data: {
						code,
						message
					}
				} = await this.$util.withdrawalWechatById(parameter)
				
				if (code === 200) {
					this.$util.showInfoToast(`提现成功`)
					this.moneyArrIndex = null
					uni.navigateBack()
				} else {
					this.$util.showInfoToast(message)
				}
			},
			previewImage(image) {
				var imgArr = [];
				imgArr.push(this.qrcodeSrc);
				//预览图片
				uni.previewImage({
					urls: imgArr,
					current: imgArr[0]
				});
			},
			//选择分享到哪里
			select(e) {
				if (e.index == 0) {
					this.$refs.share.close('share')
					this.weixin();
				}
			},
			weixin() {
				console.log("分享")
				let that = this;
				if (!that.imgsrc) {
					uni.saveImageToPhotosAlbum({
						filePath: that.qrcodeSrc,
						success: function(res1) {
							console.log(res1)
							uni.showToast({
								title: '保存相册成功'
							})
							that.imgsrc = res1.tempFilePath
							uni.share({
								provider: "weixin",
								scene: "WXSceneSession",
								type: 2,
								imageUrl: that.qrcodeSrc,
								success: function(res) {
									console.log(JSON.stringify(res));
								},
								fail: function(err) {
									console.log(JSON.stringify(err));
								}
							});
						},
						fail(res) {
							if (res.errMsg == "saveImageToPhotosAlbum:fail auth deny") {
								uni.showModal({
									title: '您需要授权相册权限',
									success(res) {
										if (res.confirm) {
											uni.openSetting({
												success(res) {

												},
												fail(res) {
													console.log(res)
												}
											})
										}
									}
								})
							}
						}
					});
				} else {
					uni.share({
						provider: "weixin",
						scene: "WXSceneSession",
						type: 2,
						title: "来自好友的分享",
						summary: "我正在使用云赚，邀你一起来看赚钱！复制到浏览器立马一起来赚钱", // 描述
						imageUrl: that.imgsrc,
						success: function(res) {
							console.log(JSON.stringify(res));
						},
						fail: function(err) {
							console.log(JSON.stringify(err));
						}
					});
				}

			},
			logoTime() {
				this.$refs.share.open()
			},
			save() {
				// #ifdef H5
				uni.showToast({
					icon: 'none',
					title: 'H5长按image保存'
				})
				return
				// #endif
				uni.saveImageToPhotosAlbum({
					filePath: this.qrcodeSrc,
					success: (res) => {
						uni.showToast({
							icon: 'success',
							title: '保存成功'
						})
					},
					fail: (err) => {
						uni.showToast({
							icon: 'none',
							title: JSON.stringify(err)
						})
					}
				})
			},
			navTo() {
				uni.navigateTo({
					url: "detail"
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		width: 100%;
		height: 100%;
	}

	.button {
		width: 450rpx;
		height: 100rpx;
		margin: 20rpx 0rpx;
		line-height: 100rpx;
		text-align: center;
		color: #FFFFFF;
		background-color: #ff5500;
		border-radius: 15rpx;
	}

	.serial-number {
		transform: scale(1.1);
		margin-right: 50rpx;
		padding-bottom: 7rpx;
	}

	.row {
		align-items: center;
		margin: 14rpx 0rpx;

		text {
			font-size: 36rpx;
		}
	}
</style>
